package com.acme.bankapp.domain.bank;

/**
 * Checking account.
 *
 */
public class CheckingAccount extends AbstractAccount {
	private final double overdraft;

	/**
	 * Creates checking account.
	 * @param amount initial amount of funds
	 * @param overdraft overdraft available to the client
	 */
	public CheckingAccount(final double amount, final double overdraft) {
		super(amount);
		this.overdraft = overdraft;
	}

	/**
	 * {@inheritDoc} It's possible for balance to go below zero, up to minus overdraft limit.
	 */
	@Override
	public void withdraw(double amount) {
		if (amount <= maximumAmountToWithdraw()) {
			if (amount <= balance) {
				super.withdraw(amount);
			} else {
				balance -= amount;
			}
		}
	}

	/**
	 * @inheritDoc
	 */
	@Override
	public double maximumAmountToWithdraw() {
		return balance + overdraft;
	}
}
